<?php
/**
 * Created by 1971599474@qq.com
 * User: zhixuan
 * Date: 2020/1/20
 * Time: 20:17
 */

namespace app\admin\controller;


use app\common\utils\JsonService;
use think\facade\Db;

class System extends Base
{
    /*
     * 配置入口
     */
    public function index()
    {
        /*配置列表*/
        $group_list = [
            //'shop_info' => '网站信息',
            'basic'     => '基本设置',
            'index_search'       => '搜索设置',
            //'shopping'  => '购物流程设置',
            //'smtp'      => '邮件设置',
            //'water'     => '水印设置',
            //'distribut' => '分销设置',
            //'push'      => '推送设置',
            //'oss'       => '对象存储'
        ];
        $this->assign('group_list',$group_list);
        $inc_type =  $this->request->param('inc_type','basic');
        $this->assign('inc_type',$inc_type);
        $config = tpCache($inc_type);
        if($inc_type == 'shop_info'){

            $province = Db::name('region')->where(array('parent_id'=>0))->select();
            $city = Db::name('region')->where(array('parent_id'=>$config['province']))->select();
            $area =  Db::name('region')->where(array('parent_id'=>$config['city']))->select();
            $this->assign('province',$province);
            $this->assign('city',$city);
            $this->assign('area',$area);
        }

        $this->assign('config',$config);//当前配置项
        //C('TOKEN_ON',false);
        return $this->fetch($inc_type);
    }

    /*
     * 新增修改配置
     */
    public function handle()
    {
        $param = $this->request->post();
        $inc_type = $param['inc_type'];

        //unset($param['__hash__']);
        unset($param['inc_type']);
        tpCache($inc_type,$param);
        $this->success("操作成功",url('admin/System/index',['inc_type'=>$inc_type]));
        //JsonService::success('配置成功');
    }
}